package com.Shuang.BS.TCP;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

//Thread 也实现了Runnable，直接继承Thread就可以 它本身就是个任务类
public class ServerRunnableThread extends Thread{
    private Socket socket;
    public ServerRunnableThread(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            //接收到浏览器请求来这,得到字节输出流去输出东西到浏览器页面
            OutputStream os = socket.getOutputStream();
            //将字节输出流包装成打印流，方便打印东西
            PrintStream ps = new PrintStream(os);
            //为了浏览器能够识别解析出来 必须遵循下面的规则才行
            ps.println("HTTP/1.1 200 OK");
            ps.println("Content-Type:text/html;charset=UTF-8");
            ps.println();  //必须换行
            ps.println("<div style='color:red;font-size:120px;text-align:center'>爽爽爽爽爽哥哥哥哥<div>");
            ps.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
